var express = require('express');
var router = express.Router();

const moment = require('moment')



const CommentModel = require('../../models')['Comment']

//发表评论
router.post('/comments', async (req, res) => {
    try {
        //接收数据
        let news_id = req.body.news_id;
        let content = req.body.content;
        //从jwt中获取用户id
        let user_id = req.auth.user_id;
        let com_time = new Date();
        const result = await CommentModel.create({
            news_id,
            content,
            user_id,
            com_time
        });
        res.cc(201, '添加成功', result)

    } catch (e) {
        res.cc(400, e.message)
    }


});


module.exports = router;